package cn.tedu._04weibo.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Lombok 生成样板代码 简化开发 提高开发效率
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    /**
     * 内部状态码，提示消息，具体数据
     */
    private Integer state;
    private String message;
    private Object data;

    public JsonResult(StatusCode statusCode,Object data) {
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
        this.data=data;
    }

    public JsonResult(StatusCode statusCode) {
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult ok(){
        return ok(null);
    }
    public static JsonResult fail(Object data){
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }


}
